package com.smarttiger.zero.admin.webservice;

import com.alibaba.fastjson.JSON;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;

import java.util.*;


public class Cxfclient {
    private static String address = "http://localhost:2006/zero-admin/services/XXS?wsdl";
    //private static String address = "http://localhost:2006/zero-admin/services/zeroapi?wsdl";
    public static void main(String[] args) {
        try {
            test();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 动态调用方式
     */
    public static void test() throws Exception {
        ClassLoader cl = Thread.currentThread().getContextClassLoader();
        Thread.currentThread().setContextClassLoader(cl);
        JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
        Client client = dcf.createClient(address);
        Object[] objects = new Object[0];

        List<Object> lp = new ArrayList<>();
        try {
            objects = client.invoke("wsApi","dddd","123456");
            System.out.println("返回数据:" + JSON.toJSONString(objects[0]));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static javax.xml.datatype.XMLGregorianCalendar getXMLGregorianCalendar(
            java.util.Date date) throws Exception {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        javax.xml.datatype.DatatypeFactory dtf = javax.xml.datatype.DatatypeFactory
                .newInstance();
        return dtf.newXMLGregorianCalendar(calendar.get(calendar.YEAR),
                calendar.get(calendar.MONTH) + 1, calendar
                        .get(calendar.DAY_OF_MONTH), calendar
                        .get(calendar.HOUR), calendar.get(calendar.MINUTE),
                calendar.get(calendar.SECOND), calendar
                        .get(calendar.MILLISECOND), calendar
                        .get(calendar.ZONE_OFFSET)
                        / (1000 * 60));
    }


}
